/**
 * @file 详情页
 */
import React, { useState, useRef } from 'react';
import styles from '../style.less';
import { connect } from 'dva';
import PostForm from '../components/PostForm';
import { LoadingModule } from '@/components';
import pageConfig from '../config/pageConfig';
const { namespace, detailName, goBackRouter } = pageConfig;
import { Button, Col, Form, Row } from 'antd';
import { router } from 'umi';

function index(props: any) {
  const {
    [namespace]: { isDetailLoading, spinning },
    actions,
  } = props;
  const [form] = Form.useForm();
  let postFormProps = {
    models: props[namespace],
    actions,
    form,
  };
  function toBack() {
    router.push(goBackRouter);
    form.resetFields();
  }
  return (
    <>
      <div className="pageTitle">{detailName}</div>
      <div className="pageBox">
        {isDetailLoading ? <LoadingModule /> : <PostForm {...postFormProps} />}
        <Row gutter={24} justify="end">
          <Col style={{ paddingRight: '13px', float: 'right' }}>
            <Button type="primary" className="btn-diy-size" onClick={toBack}>
              返回
            </Button>
          </Col>
        </Row>
      </div>
    </>
  );
}
const mapStateToProps = (props: any) => {
  return {
    [namespace]: props[namespace],
  };
};
const mapDispatchToProps = (dispatch: any) => {
  return {
    actions: {
      // fetchcateGoryId(payload: any) {
      //   dispatch({
      //     type: `${namespace}/fetchUpdateCateGoryId`,
      //     payload,
      //   });
      // },
    },
  };
};
export default connect(mapStateToProps, mapDispatchToProps)(index);
